package com.ctgu.expression;

import com.ctgu.model.entity.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("AYM")
public class AYMExpressionRoot {

    public boolean hasAuthority(String authority){
        //获取当前用户权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser =(LoginUser) authentication.getPrincipal();
        List<String> permissions = loginUser.getPermissions();
        if(permissions.contains("*:*:*")){
            return true;
        }
        return permissions.contains(authority);
        //判断用户权限集合是否存在authority

    }
}
